﻿using System;
using System.Collections.Generic;
using System.Text;

namespace POSPlus.MvcPassiveView
{
	/// <summary>
	/// Base class for controller for the Passive View.  References both the view and the model
	/// and the derivatives of this class will have several event handlers.
	/// </summary>
	/// <typeparam name="TModel"></typeparam>
	/// <typeparam name="TView"></typeparam>
	public abstract class MvcControlBase<TModel, TView>
	{
		#region Properties
		public TModel Model { get { return _model; } }
		public TView View { get { return _view; } }
		#endregion

		#region Members
		protected TView _view;
		protected TModel _model;
		#endregion

		#region Methods
		protected abstract void WireEvents();
		protected abstract void UnwireEvents();
		protected abstract void SetViewState();

		/// <summary>
		/// Connects the 3 parts of the Passive View together (model, view, control)
		/// </summary>
		/// <param name="model"></param>
		/// <param name="view"></param>
		public virtual void Initialize(TModel model, TView view)
		{
			if (_model != null || _view != null)
				UnwireEvents();

			_model = model;
			_view = view;

			SetViewState();
			WireEvents();
		}

		public void Dispose()
		{
			UnwireEvents();
		}
		#endregion
	}
}
